<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>5_2_1-为组件添加外部属性</title>
</head>

<body>


  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>

  <div id="Application">
    <my-alert title="按钮1"></my-alert>
    <my-alert title="按钮2"></my-alert>
  </div>

  <script>
    const App = Vue.createApp({}); //创建一个VUE应用
    const alertComponent = {
      //创建一个名为alertComponent的组件
      data() {
        return {
          msg: "警告框提示",
          count: 0,
        };
      },
      methods: {
        click() {
          alert(this.msg + this.count++);
        },
      },
      props: ["title"],
      template: `<div><button @click="click">{{title}}</button></div>`,
    };
    App.component("my-alert", alertComponent); //component定义组件，组件名/配置
    App.mount("#Application"); //mount方法绑定到指定实例
  </script>
</body>

</html>